package com.cl.eb.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cl.eb.mapper.EbCommentMapper;
import com.cl.eb.model.EbComment;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class CommentService {
    @Resource
    private EbCommentMapper ebCommentMapper;
    public Page list(int psize){
        //1.分页查询新闻信息
        Page page = new Page(psize,5);
        Page commentPage = ebCommentMapper.selectPage(page,
                Wrappers.<EbComment>lambdaQuery()
                        .orderByDesc(EbComment::getEcCreateTime));
        //2.返回新闻信息
        return commentPage;
    }
    /**
     * 添加 留言的业务方法
     * @param ebComment  添加的留言对象
     * @return
     */
    public boolean save(EbComment  ebComment){
        SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd  hh:mm:ss");
        ebComment.setEcCreateTime(sdf.format(new Date()));//设置系统时间
        int result = ebCommentMapper.insert(ebComment);
        return result>0?true:false;
    }
}
